#include "epoller.h"

EPoller::EPoller()
{
    m_epollFD = epoll_create(FDSIZE);
    m_events = new struct epoll_event[EPOLLEVENTS];
}

EPoller::~EPoller()
{
    delete []m_events;
    close(m_epollFD);
}

int EPoller::waitEvent()
{
    return epoll_wait(m_epollFD, m_events, EPOLLEVENTS, -1);
}

bool EPoller::addEvent(int fd,int state)
{
    struct epoll_event ev;
    ev.events = state;      //LT
    ev.data.fd = fd;
    return !epoll_ctl(m_epollFD,EPOLL_CTL_ADD,fd,&ev);
}
bool EPoller::delEvent(int fd,int state)
{
    struct epoll_event ev;
    ev.events = state;
    ev.data.fd = fd;
    return !epoll_ctl(m_epollFD,EPOLL_CTL_DEL,fd,&ev);
}
bool EPoller::mdfEvent(int fd,int state)
{
    struct epoll_event ev;
    ev.events = state;
    ev.data.fd = fd;
    return !epoll_ctl(m_epollFD,EPOLL_CTL_MOD,fd,&ev);
}
